<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a><cite>用户管理</cite></a>
    <a><cite>用户设置</cite></a>
  </div>
</div>

<script>
  var settings_url = 'agent-admin/settings';
</script>
<script type="text/html" template lay-url="{{settings_url}}" lay-done="layui.data.done(d.data)">
  <div class="layui-fluid layui-form">
    <div class="layui-form">
      {{# var settings = d.data }}
      <div class="layui-card">
        <div class="layui-card-header">
          注册
        </div>
        <div class="layui-card-body">
          <div class="layui-form-item">
            <label class="layui-form-label form-required" style="width: 120px">每日注册上限</label>
            <div class="layui-input-inline" style="width: 80px">
              <input type="text" lay-verify="required" class="layui-input" autocomplete="off"
                     name="daily_register_limit" value="{{settings.daily_register_limit || -1}}">
            </div>
            <div class="layui-inline layui-form-mid"> 设为0时表示不开放注册，设为-1表示无限制</div>
          </div>
          <div class="layui-form-item">
            <label class="layui-form-label form-required" style="width: 120px">强制渠道码注册</label>
            <div class="layui-input-inline">
              <input type="checkbox" name="channel_register_only" lay-skin="switch" lay-text="开启|关闭"
                     {{settings.channel_register_only==1?'checked':''}}>
            </div>
          </div>
        </div>
      </div>
      <div class="layui-card">
        <div style="margin-bottom: 60px"></div>
        <div class="layui-form-item">
          <div class="layui-footer">
            <div class="layui-input-block">
              <input type="button" lay-submit lay-filter="submit_settings" value="保存"
                     class="layui-btn">
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</script>
<script>
  layui.data.done = function (obj) {
    layui.use([], function () {
      let form = layui.form
        , admin = layui.admin

      form.render()

      // 提交
      form.on('submit(submit_settings)', function (data) {
        let field = data.field;
        field.channel_register_only = field.channel_register_only === 'on' ? 1 : 0
        admin.post(settings_url, field, function () {
          layer.msg('保存成功', {
            offset: '15px'
            , icon: 1
            , time: 1000
          });
        });
      });
    });
  }
</script>
